// Decompiled by GOOSIN CO,LTD Copyright 2010 Pavel Kouznetsov.
// home page: http://www.Goosin.net
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   cell_garbage_ok.java

package draft.stock;

import include.nseer_cookie.counter;
import include.nseer_cookie.exchange;
import include.nseer_db.nseer_db_backup1;
import java.io.IOException;
import java.sql.ResultSet;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import javax.servlet.jsp.JspFactory;
import validata.ValidataNumber;
import validata.ValidataTag;

public class cell_garbage_ok extends HttpServlet
{

	public cell_garbage_ok()
	{
	}

	public synchronized void service(HttpServletRequest request, HttpServletResponse response)
		throws IOException, ServletException
	{
		HttpSession dbSession = request.getSession();
		JspFactory _jspxFactory = JspFactory.getDefaultFactory();
		javax.servlet.jsp.PageContext pageContext = _jspxFactory.getPageContext(this, request, response, "", true, 8192, true);
		javax.servlet.ServletContext dbApplication = dbSession.getServletContext();
		HttpSession session = request.getSession();
		nseer_db_backup1 stock_db = new nseer_db_backup1(dbApplication);
		ValidataNumber validata = new ValidataNumber();
		counter count = new counter(dbApplication);
		ValidataTag vt = new ValidataTag();
		try
		{
			if (stock_db.conn((String)dbSession.getAttribute("unit_db_name")))
			{
				String checker_ID = (String)session.getAttribute("human_IDD");
				String config_id = request.getParameter("config_id");
				String min_amount = request.getParameter("min_amount");
				String max_amount = request.getParameter("max_amount");
				String stock_amount = request.getParameter("stock_amount");
				String design_ID = request.getParameter("design_ID");
				String product_ID = request.getParameter("product_ID");
				int num = Integer.parseInt(stock_amount);
				String designer = request.getParameter("designer");
				String bodyc = new String(request.getParameter("cell_describe").getBytes("UTF-8"), "UTF-8");
				String cell_describe = exchange.toHtml(bodyc);
				String check_time = request.getParameter("check_time");
				String checker = request.getParameter("checker");
				String serial_number_tag = request.getParameter("serial_number_tag");
				int p = 0;
				int q = 0;
				for (int i = 1; i < num; i++)
				{
					String tem_max_capacity_amount = (new StringBuilder("max_capacity_amount")).append(i).toString();
					String tem_nick_name = (new StringBuilder("nick_name")).append(i).toString();
					String tem_amount_unit = (new StringBuilder("amount_unit")).append(i).toString();
					String tem_stock_ID = (new StringBuilder("stock_ID")).append(i).toString();
					String stock_ID = request.getParameter(tem_stock_ID);
					String max_capacity_amount = request.getParameter(tem_max_capacity_amount);
					String nick_name = request.getParameter(tem_nick_name);
					String amount_unit = request.getParameter(tem_amount_unit);
					if (max_capacity_amount.equals(""))
						max_capacity_amount = "0";
					if (!validata.validata(max_capacity_amount))
						p++;
					else
					if (Double.parseDouble(max_capacity_amount) == 0.0D)
					{
						q++;
						String sql5 = (new StringBuilder("select * from stock_balance_details where stock_ID='")).append(stock_ID).append("' and product_ID='").append(product_ID).append("'").toString();
						ResultSet rs5 = stock_db.executeQuery(sql5);
						if (rs5.next())
							p++;
					} else
					if (Double.parseDouble(max_capacity_amount) < 0.0D)
						p++;
					if (nick_name.indexOf("'") != -1 || nick_name.indexOf("\"") != -1 || nick_name.indexOf(",") != -1 || amount_unit.indexOf("'") != -1 || amount_unit.indexOf("\"") != -1 || amount_unit.indexOf(",") != -1)
						p++;
				}

				if (!validata.validata(min_amount) || !validata.validata(max_amount))
					p++;
				if (vt.validata((String)dbSession.getAttribute("unit_db_name"), "stock_cell", "design_ID", design_ID, "check_tag").equals("5") || vt.validata((String)dbSession.getAttribute("unit_db_name"), "stock_cell", "design_ID", design_ID, "check_tag").equals("9"))
				{
					if (p == 0 && q < num - 1)
					{
						try
						{
							String sql = (new StringBuilder("update stock_cell set checker='")).append(checker).append("',designer='").append(designer).append("',cell_describe='").append(cell_describe).append("',min_amount='").append(min_amount).append("',max_amount='").append(max_amount).append("',check_tag='2',serial_number_tag='").append(serial_number_tag).append("' where design_ID='").append(design_ID).append("'").toString();
							stock_db.executeUpdate(sql);
							String sql4 = (new StringBuilder("select * from stock_cell where design_ID='")).append(design_ID).append("'").toString();
							ResultSet rs4 = stock_db.executeQuery(sql4);
							if (rs4.next())
								product_ID = rs4.getString("product_ID");
							for (int i = 1; i < num; i++)
							{
								String tem_nick_name = (new StringBuilder("nick_name")).append(i).toString();
								String tem_max_capacity_amount = (new StringBuilder("max_capacity_amount")).append(i).toString();
								String tem_amount_unit = (new StringBuilder("amount_unit")).append(i).toString();
								String nick_name = request.getParameter(tem_nick_name);
								String max_capacity_amount = request.getParameter(tem_max_capacity_amount);
								String amount_unit = request.getParameter(tem_amount_unit);
								if (max_capacity_amount.equals(""))
									max_capacity_amount = "0";
								String sql1 = (new StringBuilder("update stock_cell_details set nick_name='")).append(nick_name).append("',max_capacity_amount='").append(max_capacity_amount).append("',amount_unit='").append(amount_unit).append("' where design_ID='").append(design_ID).append("' and details_number='").append(i).append("'").toString();
								stock_db.executeUpdate(sql1);
							}

						}
						catch (Exception ex)
						{
							ex.printStackTrace();
						}
						response.sendRedirect("draft/stock/cell_ok.jsp?finished_tag=3");
					} else
					{
						response.sendRedirect("draft/stock/cell_ok.jsp?finished_tag=1");
					}
				} else
				{
					response.sendRedirect("draft/stock/cell_ok.jsp?finished_tag=4");
				}
				stock_db.commit();
				stock_db.close();
			} else
			{
				response.sendRedirect("error_conn.htm");
			}
		}
		catch (Exception ex)
		{
			ex.printStackTrace();
		}
	}
}
